import { Component, OnInit } from '@angular/core';
import getData_ajax from '../../common/utils/getData_ajax';
import config from '../../common/utils/baseUrl';
import { NzModalRef, NzModalService } from 'ng-zorro-antd';

@Component({
  selector: 'app-article',
  templateUrl: './article.component.html',
  styleUrls: ['./article.component.scss']
})
export class ArticleComponent implements OnInit {
    confirmModal: NzModalRef; // For testing by now
  public isSpinning:any = true; // 加载状态
  public ariticeData:any = []; // 文章数据
  constructor(private modal: NzModalService) { }

  ngOnInit() {
    this.getData();
  }

  // 拉取数据
  getData(){
    let _this = this;
    getData_ajax.getFunc(config.baseUrl+'/articleService/getArticeData','post','',function(data){
        _this.ariticeData = data.result;
        _this.isSpinning = false;
        console.log(_this.ariticeData)
      },
      function(error){
        console.log(error)
      })
  }

    /**
     * 删除文章
     */
    deleteArticleFunc(id){
        let _this = this;
        this.modal.confirm({
            nzTitle  : '确定？',
            nzContent: '<b>小哥哥，小姐姐，你确定要删除这个文章，删了就没有了.....</b>',
            nzOnOk   : () => getData_ajax.getFunc(config.baseUrl+'/articleService/deleteAritice','post',{id:id},function(data){
                    _this.modal.success({
                        nzTitle: '成功！',
                        nzContent: '小哥哥，小姐姐，你成功删除了这个文章......'
                    });
                    _this.getData();
                },
                function(error){
                    _this.modal.error({
                        nzTitle: '失败！',
                        nzContent: '小哥哥，小姐姐，待会再来删除这个文章吧......'
                    });
                })
        })
    }
}
